
let url_id1 = parseInt((location.search).slice(-1));



class Render{
    constructor(url,str,img_url){
        this.banner_img      = $(".banner-img")
        this.title_category  =  $("#title-category");
        this.goods_list_wrap = $(".goods-list-wrap");
        // console.log(this.goods_list_wrap);
        console.log(this.banner_img);
        console.log(img_url);
        $(this.banner_img).css({"background": `url(${img_url})`})
        $(this.title_category).html(str);
        this.init(url);
    }
    init(url){
        $.ajax(url).then($.proxy (function(res){
           this.rederGoodsList(res);
           new Carts();
        },this))
    }

    rederGoodsList(res){
        var res = JSON.parse(res).goods_list;
        // console.log(res);
        // console.log(res.goods_list[0].goods_path);
        // console.log(res.goods_list[0].goods_name)
        let html = "";
        $.each(res,function(index,item){
            // console.log(res[index]);
            html +=`<li class="goods-box">
            <a class="goods-link" href="http://localhost/seven/XDW/meizu_project/src/detailpage.html?id=${item.goods_id}" >
                    <img class="goods-img" src=${item.goods_path}>
                    <h3 class="item-title">${item.goods_name}</h3>
                    <p class="item-desc">${item.goods_detail}</p>
                    <p class="item-price">
                    <em>￥</em><span class="vm-price">${item.goods_price}</span>
                    </p>
            </a>
        </li>`;
        })
        // console.log(html);
        $(this.goods_list_wrap).html(html);
    }
}

if(url_id1 === 1){
    new Render("./data/data1.json","手机","https://openfile.meizu.com/group1/M00/07/37/Cgbj0F0MMouAPPnvAA0pxlZrxPs174.jpg");
}
if(url_id1 === 2){
    new Render("./data/data2.json","声学","https://openfile.meizu.com/group1/M00/07/19/Cgbj0Fy_JfeABUi1AApxslpWkjc783.jpg");
}

